package com.futures.investm.fragment;

import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.futures.investm.R;
import com.futures.investm.adapter.MtMAdapter;
import com.futures.investm.constant.Api;
import com.futures.investm.entity.MarketDatas;
import com.vise.xsnow.http.ViseHttp;
import com.vise.xsnow.http.callback.ACallback;
import com.vise.xsnow.http.mode.CacheMode;

import butterknife.BindView;
import tech.com.commoncore.base.BaseFragment;

public class RiseFragment extends BaseFragment {
    @BindView(R.id.rv_contentFastLib)
    RecyclerView recyclerView;
    MtMAdapter riseAdapter;


    public static RiseFragment newInstance() {
        Bundle bundle = new Bundle();
        RiseFragment fragment = new RiseFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public int getContentLayout() {
        return R.layout.fragment_fise_fall;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        riseAdapter = new MtMAdapter(R.layout.item_market);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        recyclerView.addItemDecoration(new DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL));


        request();
    }

    private void request() {
        ViseHttp.GET(Api.UPS_DOWNS)
                .baseUrl(Api.BASE_URL)
                .setHttpCache(true)
                .cacheMode(CacheMode.FIRST_REMOTE)
                .request(new ACallback<MarketDatas>() {
                    @Override
                    public void onSuccess(MarketDatas datas) {

                        if (1 == datas.code) {
                            MarketDatas.StealDate stealDate = datas.data;
                            riseAdapter.replaceData(stealDate.rise_data);
                        } else {
//                            ToastUtils.showToast("请求数据失败");
                        }

                    }

                    @Override
                    public void onFail(int errCode, String errMsg) {
                    }
                });
        recyclerView.setAdapter(riseAdapter);
    }

}
